package second.thread.threecore;

import lombok.Data;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @Author: heweiwei
 * @Date: 2/8/25 PM4:13
 * @Description:
 */
@Data
public class Athlete implements Runnable {

    private CyclicBarrier barrier;

    private String name;

    public Athlete(CyclicBarrier barrier, String name) {
        this.barrier = barrier;
        this.name = name;
    }

    @Override
    public void run() {
        try {
            System.out.println(name + " 已准备好，等待其他运动员...");
            // 等待其他运动员准备好
            barrier.await();
            System.out.println(name + " 开始跑步！");
        } catch (InterruptedException | BrokenBarrierException e) {
            e.printStackTrace();
        }

    }
}
